import { execute } from "../../database/connector";

import { SpecialistQueries } from "../queries/specialist.query";
import { ISpecialist } from "../../models/specialist.model";

/**
 * gets active specialist
 */
export const getSpecialists = async () => {
  return execute<ISpecialist[]>(SpecialistQueries.GetSpecialists, []);
};

/**
 * gets a specialist based on id provided
 */
export const getSpecialistById = async (id: ISpecialist['id']) => {
  return execute<ISpecialist>(SpecialistQueries.GetSpecialistById, [id]);
};

/**
 * adds a new active specialist record
 */
export const insertSpecialist = async (specialist: ISpecialist) => {
  const result = await execute<{ affectedRows: number }>(SpecialistQueries.AddSpecialist, [
    [Object.values(specialist)]
  ]);
  return result.affectedRows > 0;
};

/**
 * adds active specialists record
 */
export const insertSpecialists = async (specialists: ISpecialist[]) => {
  const result = await execute<{ affectedRows: number }>(SpecialistQueries.AddSpecialist, [specialists]);
  return result.affectedRows > 0;
};

/**
 * updates specialist information based on the id provided
 */
export const updateSpecialist = async (specialist: ISpecialist) => {
  const result = await execute<{ affectedRows: number }>(SpecialistQueries.UpdateSpecialistById, [specialist, specialist.id]);
  return result.affectedRows > 0;
};

/**
 * updates specialist information based on the id provided
 */
 export const deleteSpecialist = async (id: ISpecialist['id']) => {
  const result = await execute<{ affectedRows: number }>(SpecialistQueries.DeleteSpecialistById, [
    id
  ]);
  return result.affectedRows > 0;
};